import { useQuery } from "@tanstack/react-query";
// import { isEmpty, isNil } from "lodash";
import { RQ_GET_USER, RQ_GET_USER_NOTIFICATION } from "@/service/key";
import { apiGetUser } from "@/service/user";
import {
  apiGetUserNotification,
  getUserNotificationParams,
} from "../service/notification";

export const useGetUserResult = () => {
  const result = useQuery(
    [RQ_GET_USER],
    async () => {
      return (await apiGetUser()).data.dataInfo;
    },
    // {
    //   enabled: !isEmpty(params) && !isNil(params?.key),
    // },
  );

  return result;
};

export const useGetUserNotificationResult = (
  params: getUserNotificationParams,
) => {
  const result = useQuery({
    queryKey: [
      RQ_GET_USER_NOTIFICATION,
      params.pageNum,
      params.pageSize,
      params.subscriberName,
    ],
    queryFn: () => apiGetUserNotification(params),
    // 滞后查询，但下页查询时不显示 loading
    // keepPreviousData: true,
  });

  return result;
};
